<%@ page import="java.util.List"%>
<%@ page import="com.riq.entity.Department"%>
<%@ page import="com.riq.entity.Location"%>
<%@ page import="java.util.logging.Logger"%>
<%@ page import="java.io.IOException"%>
<%@ page import="javax.servlet.*"%>

<% Department d = (Department) request.getAttribute("dept"); 
   List<Location> locations = (List<Location>) request.getAttribute("locations");
  %>

<!--  Copyright 2010 John L. Reilly

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>FirstResponder</title>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

var startLat = "<%=d.getcoordinatesLatitude()%>";
var startLng = "<%=d.getcoordinatesLongitude()%>";
var deptLayer =  null;
var map;
var marker;

function initialize() {
  var myLatlng = new google.maps.LatLng(startLat, startLng);
  var myOptions = {
    zoom: 17,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.HYBRID
  }  

  var timestamp = new Date().getTime();
  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  placeMarker(myLatlng);

  google.maps.event.addListener(map, 'click', function(event) {
     placeMarker(event.latLng);
  });
}


function placeMarker(location) {
  if (marker) {
    marker.setPosition(location);
  } else {
    marker = new google.maps.Marker({
        position: location, 
        map: map,
        draggable: true
    });
    google.maps.event.addListener(marker, 'position_changed', showPosition);
    showPosition();
  }
}


function showPosition() {
  document.getElementById("latitude").innerHTML  = marker.getPosition().lat();
  document.getElementById("longitude").innerHTML = marker.getPosition().lng(); 
  document.getElementById("lat").value = marker.getPosition().lat();
  document.getElementById("lng").value = marker.getPosition().lng(); 
}

</script>


<!--META-->
<meta http-equiv="content-type"  content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width" />

<!--STYLESHEET-->
<link rel="stylesheet" type="text/css" href="stylesheets/static.css" />
</head>

<body onload="initialize()">

<!--FIXED HEADERS-->
<div class="headwrap">
<div class="hBlack">
<div class="headerLeftTop">FirstResponder</div>
<div class="headerRightTop">ver 0.9</div>
<div class="headerLeftBottom">Department: Edit</div>
<div class="headerRightBottom">Main</div>
</div>
<div class="hGray">
  <a class="buttonGrayHdr" href="mainMenu.html">Main</a>
  <a class="buttonGrayHdr" href="commandMenu.html">Command</a>
  <a class="buttonGrayHdr gSelected" href="department?action=display">Admin</a>
</div>
<div class="headerMist"></div>
</div>

<div class="outwrap">
<div class="headerPlug"></div>

<!--BUTTONS-->
<div id="centeredButtons"><ul><li>
<a class="button blue narrow tall first last"
   href="department?action=display">Cancel</a></li><li>
<a class="button green narrow tall first last"
   href="#" onclick="javascript:document.forms[0].submit();return false;">Save</a>
</li></ul></div>

<form method="post" action="department?action=set">
<input type=hidden name="deptId" value="<%=d.getid().toString()%>" />
<input type="hidden" id="lat" name="markerLat"></input>
<input type="hidden" id="lng" name="markerLng"></input>

<div class="row">Tracking Enabled:</div>
<div class="row">
  <input type="radio" name="trackingFlag" value="yes"
    <%if ("yes".equalsIgnoreCase(d.gettrackingFlag())) {
      out.print("checked=\"checked\""); }%>/>Yes 
      <input type="radio" name="trackingFlag" value="no"
    <%if ("no".equalsIgnoreCase(d.gettrackingFlag())) {
      out.print("checked=\"checked\""); }%>/>No</div>
<div class="row" >Short Name:</div>
<div><input class="inputfield" type="input" name="shortName" 
value="<%=d.getshortName()%>" /></div>
<div class="row" >Long Name:</div>
<div><input class="inputfield" type="input" name="longName" 
value="<%=d.getlongName()%>" /></div>
<div class="row" >Type:</div>
<div><input class="inputfield" type="input" name="type" 
value="<%=d.gettype()%>" /></div>
<div class="row" >From Email:</div>
<div><input class="inputfield" type="input" name="fromEmail" 
value="<%=d.getfromEmail()%>" /></div>
<div class="row" >Dispatch ID:</div>
<div><input class="inputfield" type="input" name="dispatchId" 
value="<%=d.getdispatchId()%>" /></div>

<!--<div class="row" >Username:</div>-->
<!--<div><input class="inputfield" type="input" name="username" -->
<!--value="<%=d.getusername()%>" /></div>-->
<!--<div class="row" >Password:</div>-->
<!--<div><input class="inputfield" type="input" name="password" -->
<!--value="<%=d.getpassword()%>" /></div>-->

<div class="row" >Mutual Aid Depts:</div>
<div><input class="inputfield" type="input" name="mutualAid" 
value="<%=d.getmutualAid()%>" /></div>
<div class="row" >Response Range 1 (mins):</div>
<div><input class="inputfield" type="input" name="distGroupA" 
value="<%=d.getdistGroupA()%>" /></div>
<div class="row" >Response Range 2 (mins):</div>
<div><input class="inputfield" type="input" name="distGroupB" 
value="<%=d.getdistGroupB()%>" /></div>
<div class="row" >Response Range 3 (mins):</div>
<div><input class="inputfield" type="input" name="distGroupC" 
value="<%=d.getdistGroupC()%>" /></div>
<div class="row" >GPS Expiration (Minutes):</div>
<div><input class="inputfield" type="input" name="distMaxAge" 
value="<%=d.getdistMaxAge()%>" /></div>

<div class="row" >Dept Latitude:</div>
<div id="latitude" class="row" style="clear: none; width: 40%; overflow: hidden"></div>

<!--<div><input class="inputfield" type="input" name="coordinatesLatitude" -->
<!--value="<%=d.getcoordinatesLatitude()%>" /></div>-->

<div class="row" >Dept Longitude:</div>
<div id="longitude" class="row" style="clear: none; width: 40%; overflow: hidden"></div>


<div class="sub white">Select Dept Position</div> 
<div class="mapWrapper" style="width: 100%; padding: 10px;">
<div style="height: 400px; width: 100%; clear:left; float: left" id="map_canvas"></div>
</div>
  

<!--<div><input class="inputfield" type="input" name="coordinatesLongitude" -->
<!--value="<%=d.getcoordinatesLongitude()%>" /></div>-->
<!--<div class="row" >Inbound VRU1:</div>-->
<!--<div><input class="inputfield" type="input"  name="inboundVRU1" -->
<!--value="<%=d.getinboundVRU1()%>" /></div>-->
<!--<div class="row" >Inbound VRU2:</div>-->
<!--<div><input class="inputfield" type="input" name="inboundVRU2" -->
<!--value="<%=d.getinboundVRU2()%>" /></div>-->
<!--<div class="row" >Inbound VRU3:</div>-->
<!--<div><input class="inputfield" type="input" name="inboundVRU3" -->
<!--value="<%=d.getinboundVRU3()%>" /></div>-->
</form>

<!--BUTTONS-->
<div id="centeredButtons"><ul><li>
<a class="button blue narrow tall first last"
   href="department?action=display">Cancel</a></li><li>
<a class="button green narrow tall first last"
   href="#" onclick="javascript:document.forms[0].submit();return false;">Save</a>
</li></ul></div>

<!--FOOTER-->
<div class="footer">FirstResponder</div>

<!--OUTLINE WRAPPER -->
</div> 

</body>
</html>
